<template>
<div>
  <div>
    <h2>支付宝支付</h2>
    <div>
      <input v-model="pay.title" placeholder="请输入标题">
    </div>
    <div>
      <input v-model="pay.no" placeholder="请输入订单号">
    </div>
    <div>
      <input v-model="pay.money" placeholder="请输入金额">
    </div>
    <div><button @click="add()">发起支付</button></div>
  </div>
  <div>
    <h2>查询支付状态</h2>
    <div>
      <input v-model="pay.no" placeholder="请输入订单号">
    </div>
    <div><button @click="query()">查询支付状态</button></div>
  </div>
  <div>
    <h2>发起退款</h2>
    <div>
      <input v-model="pay.no" placeholder="请输入订单号">
      <input v-model="money" type="number" placeholder="请输入退款金额">
    </div>
    <div><button @click="refund()">发起退款</button></div>
  </div>
</div>
</template>

<script>
export default {
  name: "PayView",

  data(){
    return{
      order:{
        name:"",
        addid:1,
        info:"多放辣",
        gprice:120,
        gimage:"123123",
        gname:"123123",
        goods:[
          {
            gid:1,
            gnum:2,
          },{
            gid:2,
            gnum:2,
          }
        ],
      },
      pay:{
        no:"",
        money:0,
        title:""
      },
    money:0
    }
  },methods:{
    add(){
      this.axios.post("/pay/createpay.do",this.pay).then(r=>{
        if(r.data.code=200){
          //创建支付成功
          this.name = r.data.data;
          alert(name)
          this.$router.push()

        }
      }),
          this.axios.post("/order/add.do",this.order).then( (r)=>{
            if (r.data.code == 200){
              alert("支付成功")
            }
          }),
          this.$router.push({path:"/paysuccess",param:{order:order}});
    },
    query(){
      this.axios.get("/pay/query.do?no="+this.pay.no).then(r=>{
        if(r.data.code=200){
          this.$toast(r.data.data);
        }
      })
    },
    refund(){
      //退款
      this.axios.get("/pay/refund.do?no="+this.pay.no+"&money="+this.money).then(r=>{
        if(r.data.code=200){
          this.$toast(r.data.data);
        }else {
          this.$toast(r.data.data);
        }
      })
    }
  }
}
</script>

<style scoped>

</style>